import React, { PureComponent } from 'react';
import cx from 'classnames';
import assets from '@/modules/assets';
import intf from '@/modules/interface';
import navigator from '@/modules/navigator';
import WebGl from '@/modules/three';
import utils from '@/modules/utils';
import config from '../config';
// import store from '../modules/store';
// import { _, cx, is, moment, qs, globalData, requestPayment, filterObject, tools, checkUpdate } from '../modules/utils';

/**
 * Base Component，为所有业务组件封装通用功能
 *
 * @export
 * @class Base
 * @extends {Component}
 */
export default class Base<P = {}, S = {}> extends PureComponent<P, S> {
  /**
   * 全局变量
   *  set: this.globalData.set('a',b)
   *  get: this.globalData.get('a')
   * @protected
   * @memberof Base
   */
  // protected readonly globalData = globalData;

  /**
   * api 请求工具
   *
   * @protected
   * @memberof Base
   */
  // protected readonly apiClient = apiClient;

  protected readonly AppConfig = config;

  /**
   * 静态资源访问器
   *
   * @protected
   * @memberof Base
   */
  protected readonly assets = assets;

  /**
   * 接口方法
   *
   * @protected
   * @memberof Base
   */
  protected readonly interface = intf;

  /**
   * 工具
   *
   * @protected
   * @memberof Base
   */
  protected readonly utils = utils;

  /**
   * 可交互弹窗, 如 modal，loading， toast 等
   *
   * @protected
   * @memberof Base
   */
  // protected readonly feedback = {
  //   showFeedback: feedbackObservable.show,
  //   hideFeedback: feedbackObservable.hide,
  //   toggleFeedback: feedbackObservable.toggle,
  //   hideLoading: feedbackModule.hideLoading,
  //   hideToase: feedbackModule.hideToast,
  //   showActionSheet: feedbackModule.showActionSheet,
  //   showLoading: feedbackModule.showLoading,
  //   showModal: feedbackModule.showModal,
  //   showToast: feedbackModule.showToast,
  // };

  /**
   * 导航接口，页面跳转相关
   *
   * @protected
   * @memberof Base
   */
  protected readonly navigator = navigator;

  /**
   * WebGl
   *
   * @protected
   * @memberof Base
   */
  protected readonly WebGl = WebGl;

  /**
   * 存储接口
   *
   * @protected
   * @memberof Base
   */
  // protected readonly store = store;

  /**
   * classnames
   *
   * @protected
   * @memberof Base
   */
  protected readonly cx = cx;

  /**
   * 组件 mount 事件
   */
  public componentDidMount() {
    this.didMount();
  }

  public componentWillUnmount() {
    this.willUnmount();
  }

  /**
   * 组件 show 事件
   */
  public componentDidShow() {
    this.didShow();
  }

  /**
   * 组件 hide 事件
   */
  public componentDidHide() {
    this.didHide();
  }
  /**
   * 更新 state
   *
   * @protected
   * @memberof Base
   */
  protected readonly updateState = (newState: any) =>
    new Promise((resolve) => {
      this.setState(newState, resolve);
    });

  protected didMount() {}
  protected didShow() {}
  protected didHide() {}
  protected willUnmount() {}
}
